package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.TbCourseType;
import com.ruoyi.product.service.ITbCourseTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 课程类别Controller
 * 
 * @author Sun
 * @date 2023-01-30
 */
@RestController
@RequestMapping("/type")
public class TbCourseTypeController extends BaseController
{
    @Autowired
    private ITbCourseTypeService tbCourseTypeService;

    /**
     * 查询课程类别列表
     */
    @RequiresPermissions("product:type:list")
    @GetMapping("/list2")
    public TableDataInfo list(TbCourseType tbCourseType)
    {
        startPage();
        List<TbCourseType> list = tbCourseTypeService.selectTbCourseTypeList(tbCourseType);
        return getDataTable(list);
    }

    /**
     * 导出课程类别列表
     */
    @RequiresPermissions("product:type:export")
    @Log(title = "课程类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export2")
    public void export(HttpServletResponse response, TbCourseType tbCourseType)
    {
        List<TbCourseType> list = tbCourseTypeService.selectTbCourseTypeList(tbCourseType);
        ExcelUtil<TbCourseType> util = new ExcelUtil<TbCourseType>(TbCourseType.class);
        util.exportExcel(response, list, "课程类别数据");
    }

    /**
     * 获取课程类别详细信息
     */
    @RequiresPermissions("product:type:query")
    @GetMapping(value = "/getInfo2/{courseTypeId}")
    public AjaxResult getInfo(@PathVariable("courseTypeId") Long courseTypeId)
    {
        return success(tbCourseTypeService.selectTbCourseTypeByCourseTypeId(courseTypeId));
    }

    /**
     * 新增课程类别
     */
    @RequiresPermissions("product:type:add")
    @Log(title = "课程类别", businessType = BusinessType.INSERT)
    @PostMapping("/add2")
    public AjaxResult add(@RequestBody TbCourseType tbCourseType)
    {
        return toAjax(tbCourseTypeService.insertTbCourseType(tbCourseType));
    }

    /**
     * 修改课程类别
     */
    @RequiresPermissions("product:type:edit")
    @Log(title = "课程类别", businessType = BusinessType.UPDATE)
    @PutMapping("/edit2")
    public AjaxResult edit(@RequestBody TbCourseType tbCourseType)
    {
        return toAjax(tbCourseTypeService.updateTbCourseType(tbCourseType));
    }

    /**
     * 删除课程类别
     */
    @RequiresPermissions("product:type:remove")
    @Log(title = "课程类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove2/{courseTypeIds}")
    public AjaxResult remove(@PathVariable Long[] courseTypeIds)
    {
        return toAjax(tbCourseTypeService.deleteTbCourseTypeByCourseTypeIds(courseTypeIds));
    }
}
